<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

/**
 * Content Component HTML Helper
 *
 * @static
 * @package		Joomla
 * @subpackage	    Content
 * @since 1.5
 */
class JHTMLTourField
{
	var $content;
	var $conf;
	var $mode;
	var $plugins;
	var $itemid;
	
	function JHTMLTourField($conf,$mode,$plugins,$itemid,$baseurl) {
		$this->conf 		= $conf;
		$this->mode 		= $mode;
		$this->modetitle 	= 2 - $mode;//if $mode = 0 (list) => modetitle = 2 only title, //if $mode = 1 (details) => modeltitle = 1 (details)
		$this->plugins 		= $plugins;
		$this->itemid 		= $itemid;
		$this->baseurl 		= $baseurl;
	}
	
	public static function getFieldValues($id){
		$db = JFactory::getDbo();
		if($id){
			$db->setQuery("SELECT * FROM #__travel_field_values WHERE fieldid = ".(int)$id);
			return $values = $db->loadObjectList();
		}
	}
	
	function showFieldForm($field,$content,$default)
	{
		$return = "";
		$strtitle = JText::_($field->field_title);
		$name = $field->field_name;
		$value = "@\$content->".$name;
		eval("\$value = \"\".$value;");
		echo $value = JText::_($value);
		
		$fieldName = "jform[$name]";
		$fieldId = "jform_$name";
		
		$star = '';
		$required = '';
		if ($field->required == 1){
			$star 		= "<span class='star'>*</span>";
			$required	= "required";
		}
		$label = "<label id='jform_".$name."-lbl' for='jform_".$name."' class=''>$strtitle $star</label>";
		
		switch ($field->field_type)
		{
			case 'checkbox':
				
				if ($value == 1)
					$return .= "$label <input class='inputbox $required' type='checkbox'  checked='checked' id='$fieldId' name='$fieldName' value='1' />\n";
				else
					$return .= "$label <input class='inputbox $required' type='checkbox'  name='$fieldName' id='$fieldId' value='1' />\n";
				break;

			case 'multicheckbox':
				$fieldValues = $this->getFieldValues($field->id);
				$return = "$label <ul class='multicheckbox'>";
				foreach($fieldValues as $fieldValue){
					if ($value == 1)
						$return .= "<li><input class='inputbox' type='checkbox'  checked='checked' id='".$fieldId."[]' name='".$fieldName."[]' value='$fieldValue->field_value' /><label>$fieldValue->field_title</label></li>";
					else
						$return .= "<li><input class='inputbox' type='checkbox'  name='".$fieldName."[]' id='".$fieldId."[]' value='".$fieldValue->field_value."' /><label>$fieldValue->field_title</label></li>";
				}
				$return .= "</ul>";
				break;
				
			case 'editor':
				
				$editor =& JFactory::getEditor();
				$return .= $label.'<div class="clr"></div>'.$editor->display($fieldName, $value, '100%', '250px', $field->cols, $field->rows);
				break;
				
			case 'text':
				if ($field->required == 1)
					$return .= "$label <input class='$required' mosReq='1' name='$fieldName' id='$fieldId' type='text' mosLabel='$strtitle'  size='$field->field_size' maxlength='$field->field_maxlength' value='".htmlspecialchars($value,ENT_QUOTES)."' />\n";
				else
					$return .= "$label <input class='$required' name='$fieldName' id='$fieldId' type='text'  mosLabel='$strtitle' size='$field->field_size' maxlength='$field->field_maxlength' value='".htmlspecialchars($value,ENT_QUOTES)."' />\n";
				break;
		}
		return $return;
	}
}
